//按钮事件新增或编辑
var B2C203_type = "";
//其他页面传到本页面参数
var B2C203_param = {};
//暂时没用
var B2C203_validate = "";
//当前触发按钮
var B2C203_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var B2C203_ary_IS_TREE = [{"MAIN_ID":"0","CN_NAME":"否"},{"MAIN_ID":"1","CN_NAME":"是"}];
var B2C203_ary_TREE_COND = [{"MAIN_ID":"0","CN_NAME":"弹窗树"},{"MAIN_ID":"1","CN_NAME":"左右树"}];

/*declare select options end*/

//输入框默认值
function B2C203_input_default(){
	//所有输入框设置默认值
	/*Input Default Begin*/
	$("#B2C203_IS_TREE").val('0');
	$("#B2C203_TREE_COND").val('0');
	/*Input Default End*/
}

//主从表传递参数
function B2C203_param_set(){
	/*Main Subsuv Table Param Begin*/
    $("#B2C203_find_TABLE_ID_cn_name").val("");
    $("#B2C203_TABLE_ID").val("-1");
    if(B2C203_param.hasOwnProperty("TABLE_ID_cn_name"))
        $("#B2C203_find_TABLE_ID_cn_name").val(s_decode(B2C203_param["TABLE_ID_cn_name"]));
    if(B2C203_param.hasOwnProperty("TABLE_ID"))
        $("#B2C203_TABLE_ID").val(B2C203_param["TABLE_ID"]);					
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function B2C203_t_single_expand_biz_start(inputdata) {
	B2C203_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    $.each(B2C203_ary_IS_TREE, function (i, obj) {
        addOptionValue("B2C203_IS_TREE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
    });
    $.each(B2C203_ary_TREE_COND, function (i, obj) {
        addOptionValue("B2C203_TREE_COND", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
    });
    B2C203_init_t_single_expand()
	
    /*biz end*/
}

/*biz step begin*/
function B2C203_format_IS_TREE(value, row, index) {
    var objResult = value;
    for(i = 0; i < B2C203_ary_IS_TREE.length; i++) {
        var obj = B2C203_ary_IS_TREE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function B2C203_format_TREE_COND(value, row, index) {
    var objResult = value;
    for(i = 0; i < B2C203_ary_TREE_COND.length; i++) {
        var obj = B2C203_ary_TREE_COND[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}


/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function B2C203_page_end(){
	page_btn_priv("B2C203");
	B2C203_get_edit_info();
}

//页面初始化方法
function B2C203_init_t_single_expand() {
	//输入框默认值
	B2C203_input_default();
	//参数传递
	B2C203_param_set();	
	//表单验证
	B2C203_checkFormInput();
	//结束函数
	B2C203_page_end();
}

//提交表单数据
function B2C203_SubmitForm(){
	if($("#B2C203_MAIN_ID").val() == ""){
		var inputdata = {
				"param_name": "N01_ins_t_single_expand",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": $("#B2C203_IS_TREE").val()
                ,"param_value2": s_encode($("#B2C203_P_NODE").val())
                ,"param_value3": s_encode($("#B2C203_C_NODE").val())
                ,"param_value4": $("#B2C203_TABLE_ID").val()
                ,"param_value5": s_encode($("#B2C203_S_NAME").val())
                ,"param_value6": $("#B2C203_TREE_COND").val()
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "B2C203_get_N01_ins_t_single_expand");
	}
	else{
		var inputdata = {
				"param_name": "N01_upd_t_single_expand",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": $("#B2C203_IS_TREE").val()
                ,"param_value2": s_encode($("#B2C203_P_NODE").val())
                ,"param_value3": s_encode($("#B2C203_C_NODE").val())
                ,"param_value4": $("#B2C203_TABLE_ID").val()
                ,"param_value5": s_encode($("#B2C203_S_NAME").val())
                ,"param_value6": $("#B2C203_TREE_COND").val()
                ,"param_value7": $("#B2C203_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "B2C203_get_N01_upd_t_single_expand");
	}
}

//vue回调
function B2C203_t_single_expand_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
}

//for表单提交
$("#B2C203_save_t_single_expand_Edit").click(function () {
	$("form[name='B2C203_DataModal']").submit();
})

/*修改数据*/
function B2C203_get_N01_upd_t_single_expand(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_single_expand) == true)
	{
		swal("修改数据成功!", "", "success");
		B2C203_clear_validate();
		layer.close(B2C203_param["ly_index"]);
	}
}

/*添加数据*/
function B2C203_get_N01_ins_t_single_expand(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_single_expand) == true)
	{
		swal("添加数据成功!", "", "success");
		B2C203_clear_validate();
		layer.close(B2C203_param["ly_index"]);
	}
}

//取消编辑
$("#B2C203_cancel_t_single_expand_Edit").click(function () {
	layer.close(B2C203_param["ly_index"]);
	B2C203_clear_validate();
	$("[id^='B2C203_div']").hide();
})

//清除查找框
function B2C203_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function B2C203_clear_validate(){
	$("#B2C203_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#B2C203_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#B2C203_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function B2C203_clear_edit_info(){
	var inputs = $("#B2C203_DataModal").find('input');
	var selects = $("#B2C203_DataModal").find("select");
	var textareas = $("#B2C203_DataModal").find('textarea');
	var divs = $("div[id^='B2C203'][id$='FILE_div']");  
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	$.each(divs, function (i, obj) {
		$(obj).html("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
	
	/*input validate clear end*/
}

//从后台获取单表数据
function B2C203_get_edit_info(){
	//N01_sel_t_single_expand_ByID
	var inputdata = {
		"param_name": "N01_sel_t_single_expand_ByID",
		"session_id": session_id,
		"login_id": login_id
        ,"param_value1": $("#B2C203_TABLE_ID").val()
        	
            /*update param end*/
	};
	get_ajax_baseurl(inputdata, "B2C203_N01_sel_t_single_expand_ByID");
}

//获取单表数据
function B2C203_N01_sel_t_single_expand_ByID(input){
	if (Call_QryResult(input.N01_sel_t_single_expand_ByID) == true){
		if(input.N01_sel_t_single_expand_ByID.length > 0){
			$("#B2C203_MAIN_ID").val(input.N01_sel_t_single_expand_ByID[0].MAIN_ID);
			$("#B2C203_IS_TREE").val(input.N01_sel_t_single_expand_ByID[0].IS_TREE);
			$("#B2C203_P_NODE").val(s_decode(input.N01_sel_t_single_expand_ByID[0].P_NODE));
			$("#B2C203_C_NODE").val(s_decode(input.N01_sel_t_single_expand_ByID[0].C_NODE));
			$("#B2C203_S_NAME").val(s_decode(input.N01_sel_t_single_expand_ByID[0].S_NAME));
			$("#B2C203_TREE_COND").val(s_decode(input.N01_sel_t_single_expand_ByID[0].TREE_COND));
		}
		else{
			$("#B2C203_MAIN_ID").val("");
			$("#B2C203_IS_TREE").val("0");
			$("#B2C203_P_NODE").val("");
			$("#B2C203_C_NODE").val("");
			$("#B2C203_S_NAME").val("");
			$("#B2C203_TREE_COND").val("0");
		}
	}
}

//form验证
function B2C203_checkFormInput() {
    B2C203_validate = $("#B2C203_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            B2C203_MAIN_ID: {}
            ,B2C203_TABLE_ID: {digits: true,required : true,maxlength:10}
            ,B2C203_IS_TREE: {}
            ,B2C203_P_NODE: {maxlength:50}
            ,B2C203_C_NODE: {maxlength:50}
            ,B2C203_S_NAME: {maxlength:50}
            ,B2C203_TREE_COND: {}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            B2C203_MAIN_ID: {}
            ,B2C203_TABLE_ID: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,B2C203_IS_TREE: {}
            ,B2C203_P_NODE: {maxlength:"长度不能超过50"}
            ,B2C203_C_NODE: {maxlength:"长度不能超过50"}
            ,B2C203_S_NAME: {maxlength:"长度不能超过50"}
            ,B2C203_TREE_COND: {}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	B2C203_SubmitForm();
        	return false;
        }
    })
}